<script setup lang="ts">
import { ref } from "vue";
import { staticParkEntryConfig } from "./utils/hook";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { usePublicHooks } from "../../../hooks";
import { usePublicFormats } from "../../../formats";
import { PureTableBar } from "@/components/RePureTableBar";

import Refresh from "@iconify-icons/ep/refresh";

defineOptions({
  name: "parkingRecordStaticParkEntry"
});

const formRef = ref();
const { timeFrame } = usePublicHooks();

const { carColorOptions, orderTypeOptions } = usePublicFormats();

const {
  columns,
  form,
  loading,
  onSearch,
  resetForm,
  dataList,
  pagination,
  onSizeChange,
  onCurrentChange,
  loadingConfig
} = staticParkEntryConfig();
</script>

<template>
  <div>
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]"
      :header-cell-style="{
        background: 'var(--el-fill-color-light)',
        color: 'var(--el-text-color-primary)'
      }"
    >
      <el-form-item label="车牌号" prop="car_number" class="!w-[20%]">
        <el-input
          v-model="form.car_number"
          placeholder="请输入车牌号"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item label="车牌颜色" prop="car_no_color" class="!w-[20%]">
        <el-select
          v-model="form.car_no_color"
          placeholder="请选择车牌颜色"
          clearable
          class="!w-[160px]"
        >
          <el-option
            v-for="item in carColorOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="停车场名称" prop="park_name" class="!w-[20%]">
        <el-input
          v-model="form.park_name"
          placeholder="请输入停车场名称"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>

      <el-form-item label="流水号" prop="serial_no" class="!w-[20%]">
        <el-input
          v-model="form.serial_no"
          placeholder="请输入流水号"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item label="区域编号" prop="region_code" class="!w-[20%]">
        <el-input
          v-model="form.region_code"
          placeholder="请输入区域编号"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item label="订单号" prop="order_no" class="!w-[20%]">
        <el-input
          v-model="form.order_no"
          placeholder="请输入订单号"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item label="订单类型" prop="order_type" class="!w-[20%]">
        <el-select
          v-model="form.order_type"
          placeholder="请选择订单类型"
          clearable
          class="!w-[160px]"
        >
          <el-option
            v-for="item in orderTypeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="商户编号" prop="much_id" class="!w-[20%]">
        <el-input
          v-model="form.much_id"
          placeholder="请输入商户编号"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item label="入场时间" prop="in_time" class="!w-[40%]">
        <el-date-picker
          v-model="form.in_time"
          type="datetimerange"
          :shortcuts="timeFrame"
          format="YYYY-MM-DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
          range-separator="至"
          start-placeholder="开始日期时间"
          end-placeholder="结束日期时间"
          :popper-options="{
            placement: 'bottom-start'
          }"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon('ri:search-line')"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>
    <PureTableBar title="进场记录" :columns="columns" @refresh="onSearch">
      <pure-table
        v-if="dataList.length > 0"
        ref="tableRef"
        stripe
        row-key="id"
        alignWhole="center"
        showOverflowTooltip
        :loading="loading"
        :loading-config="loadingConfig"
        :columns="columns"
        :data="dataList"
        :header-cell-style="{
          background: 'var(--el-fill-color-light)',
          color: 'var(--el-text-color-primary)'
        }"
        :pagination="pagination"
        @page-size-change="onSizeChange"
        @page-current-change="onCurrentChange"
      >
        <template #image="{ row, index }">
          <el-image
            preview-teleported
            loading="lazy"
            :src="row.in_photo"
            :preview-src-list="dataList.map(v => v.in_photo)"
            :initial-index="index"
            fit="cover"
            class="w-[50px] h-[50px]"
          />
        </template>
      </pure-table>
    </PureTableBar>
  </div>
</template>
